package com.bj.dljd.util;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {

    @Autowired
    private RedisTemplate redisTemplate;


    public int add(String key, Map<String,String> map){

        try {
            HashOperations hashOperations = redisTemplate.opsForHash();
            hashOperations.putAll(key,map);
            redisTemplate.expire(key,120, TimeUnit.MINUTES);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
        return 1;
    }
    public int delete(String key){
        try {
            HashOperations hashOperations = redisTemplate.opsForHash();
            hashOperations.delete(key);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
        return 1;
    }


}
